package com.example.springstudy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.springstudy.entity.Supplier;
import com.example.springstudy.mapper.SupplierMapper;
import com.example.springstudy.service.SupplierService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> implements SupplierService {

    @Override
    public List<Supplier> findAll() {
        return this.list(new LambdaQueryWrapper<Supplier>().orderByAsc(Supplier::getId));
    }

    @Override
    public int add(Supplier superior) {
        this.save(superior);
        return superior.getId();
    }

    @Override
    public int delete(int id) {
        Supplier superior = this.getOne(new LambdaQueryWrapper<Supplier>().eq(Supplier::getId, id));
        superior.setIsDeleted(1);
        this.updateById(superior);
        return superior.getId();
    }

    @Override
    public int update(Supplier superior) {
        this.updateById(superior);
        return superior.getId();
    }

    @Override
    public Supplier getOneByName(String name) {
        return this.getOne(new LambdaQueryWrapper<Supplier>().eq(Supplier::getName, name));
    }
}
